package com.lupan.mutithred.cp2_CountDownLatch;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * 说明：
 *
 * @author lupan
 * @version 2017/4/24 16:11
 */
public class CBThread extends Thread {

    private CyclicBarrier cb;

    public CBThread(CyclicBarrier cb) {
        this.cb = cb;
    }

    @Override
    public void run() {
        try {
            System.out.println(Thread.currentThread().getName() + " 到了！等待其他线程到达。。。");
            cb.await();
            System.out.println(Thread.currentThread().getName() + " 已经凑齐两个线程，程序向下执行。。。");
        } catch (InterruptedException | BrokenBarrierException e) {
            e.printStackTrace();
        }
    }
}
